package com.aiit.controller.admin;

import com.aiit.dto.TeaOrderDTO;
import com.aiit.entity.TeaOrder;
import com.aiit.result.Result;
import com.aiit.service.OrderService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/shop")
@Api(tags = "通用接口")
@Slf4j
public class OrderController2 {

    @Autowired
    private OrderService orderService;

    @GetMapping("/orders")
    @ApiOperation("会员订单查询")
    public Result<Page<TeaOrder>> orders(TeaOrderDTO teaOrderDTO) {
        Page<TeaOrder> orderResult = orderService.adminOrder(teaOrderDTO);
        return Result.success(orderResult);
    }

    @PutMapping("/payment/update")
    @ApiOperation("下单成功后的请求")
    public Result UpdatePayment2(@RequestParam(required = false) String username, @RequestParam(required = false) Long id) {
        TeaOrderDTO teaOrderDTO = new TeaOrderDTO();
        teaOrderDTO.setUsername(username);
        teaOrderDTO.setId(id);
        log.info("修改订单状态信息信息：{}", username, id);
        orderService.updatePayment(teaOrderDTO);

        return Result.success();
    }

    @PutMapping("/deliver/update")
    @ApiOperation("下单成功后的请求")
    public Result Updatedeliver(@RequestParam(required = false) String username, @RequestParam(required = false) Long id) {
        TeaOrderDTO teaOrderDTO = new TeaOrderDTO();
        teaOrderDTO.setUsername(username);
        teaOrderDTO.setId(id);
        log.info("修改订单状态信息信息：{}", username, id);
        orderService.updateDeliver(teaOrderDTO);

        return Result.success();
    }
}
